home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
8bitfiles.net/archives
/
archives.tar
/
archives
/
genie-commodore-file-library
/
C64Toolkit
/
DOSIT54.ARC
/
_DIR SORT
(
.txt
)
next >
Wrap
Commodore BASIC
|
2019-04-13
|
9KB
|
237 lines
1 POKE53265,27
10 POKE55,0:POKE56,60:POKE643,0:POKE644,60:CLR:REM LOWER MEMORY TOP FOR ALT SCREEN
15 POKE53281,6:POKE53280,14:PRINT""CHR$(142)CHR$(8);:REM SET COLORS,DISABLE L/C
20 REM*******LOAD MACHINE LANGUAGE PROGRAM INTO MEMORY*************************
30 GOSUB1290:GOTO270
40 REM*******SUBROUTINE: READ DIRECTORY FROM DISK******************************
50 CLOSE5:OPEN5,8,5,"#":S%(1)=1:DE=0:I=1:REM SECTOR 1, DIRECTORY ENTRY 0
55 PRINT"[147]";:ME$="READING DIRECTORY":GOSUB 1220
60 PRINT#15,"U1:";5;0;18;S%(I):I=I+1:GOSUB1262:IFERTHEN850
70 GET#5,T$:GET#5,S$:S%(I)=ASC(S$+CHR$(0))
80 FORQ=1TO8:DE=DE+1:DR$(DE)=""
90 SYS896:DR$(DE)=A$
100 IFQ<>8THENGET#5,NG$,NG$
110 NEXT Q:IFS%(I)<21THEN60
120 CLOSE5
130 RETURN
140 REM*******SUBROUTINE: DISPLAY DIRECTORY ***********************************
150 IFALTHENGOSUB1190
155 PRINT"[147]";:TA=0
160 FORQ=1TOG
170 IFQ=24ORQ=70THENTA=20:PRINT"";
180 IFQ=47THENGOSUB1190:PRINT"";:TA=0
190 PRINTTAB(TA)"[155]"RIGHT$(STR$(Q),2)" "MID$(DR$(SC%(Q)),4,16):REM PRINT NAMES
200 NEXTQ
210 RETURN
220 CLOSE5:RETURN
230 REM
240 REM
250 REM
260 REM*************INITIALIZE*************************************************
270 DIM DR$(145),S%(20),NM$(145),SO%(145),SC%(145)
280 AL=0:GOSUB1190:PRINT"[147]";:GOSUB1190:REM CLEAR ALT. SCREEN
290 SP$=" "
300 VE$=""
305 GOSUB1490
320 GETJ$:IFJ$=""THEN320
325 IFJ$="I"THENGOSUB1700:GOTO305:REM PRINT INSTRUCTIONS IF REQUESTED
330 CLOSE15:OPEN15,8,15,"I":REM COMMAND CHAN.
340 REM********READ IN DIRECTORY***********************************************
350 GOSUB50:REM READ THE DIRECTORY FROM DISK INTO DR$() ARRAY
360 REM****** BUILD SCREEN POSITION ARRAY *************************************
370 G=0:D=0:REM SORT ENTRIES INTO GOOD PILE AND DELETED PILE
380 FORJ=1TODE
390 A=ASC(DR$(J)+CHR$(0)):IFA<128THEND=D+1:SO%(D)=J:GOTO410
400 G=G+1:SC%(G)=J
410 NEXTJ
415 IFG>46THENPG=1:IFG>92THENPRINT"[147] OVER 92 ENTRIES - CAN'T DO":GOTO850
420 D=0:FORJ=G+1TODE:D=D+1:SC%(J)=SO%(D):NEXTJ:REM DELETED ENTRIES AT END OF ARRAY
430 REM********DISPLAY UNSORTED DIRECTORY**************************************
440 GOSUB 150:IFPGTHENGOSUB1215:REM PRINT THE DIRECTORY
450 REM********PRESENT MENU CHOICES********************************************
460 ME$="(1) ALPHABETIZE OR (2) CUSTOM SORT?"
470 GOSUB1220:GOSUB1160:ONVAL(Q$)GOTO510,910:IFPGTHENIFQ$="[133]"THENGOSUB1190:GOSUB1215
475 GOTO460
480 REM
490 REM
500 REM
510 REM*******ALPHABETIZE******************************************************
515 ME$="[146] [145]":GOSUB 1220
520 ME$="..PREPARING FOR SORT -- PLEASE WAIT..":GOSUB1220
530 FOR X=1TOG:REM LOOP TO CONVERT FILE NAMES
540 NM$(X)=MID$(DR$(SC%(X)),4,16)
550 FORP=2TO17:REM LOOP TO HACK SHIFTED SPACES FROM END
560 IFMID$(NM$(X),P,1)=CHR$(160)THENNM$(X)=MID$(NM$(X),1,P-1):GOTO580
570 NEXT P
580 NEXT X
590 ME$=".........NOW SORTING.........":GOSUB1220
600 REM SHELL SORT
620 B=G
630 B=INT(B/2):PRINTVE$;""MID$(STR$(B),2)"[146] ";:IFB=0THEN690
640 X=1:K=G-B
645 C=X
650 D=C+B:IFNM$(C)<=NM$(D)THEN670
660 H%=SC%(C):SC%(C)=SC%(D):SC%(D)=H%
665 HO$=NM$(C):NM$(C)=NM$(D):NM$(D)=HO$:C=C-B:IFC>0THEN650
670 X=X+1:IFX>KTHEN630
672 GOTO645
673 REM
674 REM
680 REM*******DISPLAY SORTED DIRECTORY*****************************************
690 GOSUB150
692 ME$="OKAY? Y/N":GOSUB1220:IFPGTHENGOSUB1215
695 GOSUB1160:IFPGTHENIFQ$="[133]"THENGOSUB1190:GOTO692
700 IFQ$<>"Y"THEN910
710 REM*******WRITE NEW DIRECTORY TO DISK**************************************
720 OPEN5,8,5,"#":REM FILE CHAN.
730 W=I-1:DW=0:REM W=NUMBER OF BLOCKS TO WRITE
740 FOR I=1TOW:PRINT#15,"B-P:";5;0:REM LOOP TO WRITE. FORCE BUF POINT TO BEGIN
750 TT=18:IFS%(I+1)=255THENTT=0:REM TRACK # TO WRITE. 0 IF LAST BLOCK
760 PRINT#5,CHR$(TT);CHR$(S%(I+1));:REM PUT THE TRACK AND NEXT SECTOR
770 FOR Q=1TO8:DW=DW+1:REM LOOP TO PUT THE DIR ENTRIES
780 PRINT#5,DR$(SC%(DW));:REM PUT THE ENTRY
790 IFQ<>8THENPRINT#5,"SG";:REM PUT IN 2 DUMMY BYTES
800 NEXT Q
810 PRINT#15,"U2:";5;0;18;S%(I):GOSUB1262:IF ERTHEN850
820 ME$="WRITING SECTOR: "+STR$(S%(I)):GOSUB1220
830 NEXT I
840 REM************EXIT********************************************************
850 ME$="D O N E":GOSUB1220:IFPGTHENGOSUB1200
860 POKE56,160:POKE644,160:PRINTVE$;:CLOSE5:CLOSE15:PRINTCHR$(9);:GOTO9000
870 REM
880 REM
890 REM
900 REM****** INPUT CUSTOM SORT ***********************************************
910 ME$="RENUMBER ENTRIES, THEN PRESS <F7>"
920 GOSUB1220:PRINT"";
930 SYS938:IFPEEK(780)=136THENME$="...RE-SORTING...":GOSUB1220:GOTO970
940 IFPGTHENIFPEEK(780)=133THENGOSUB1190:GOTO920
950 GOTO930
960 REM*******RE-SORT ACCORDING TO NEW ORDER***********************************
970 FORJ=1TOG:SO%(J)=0:NEXTJ:REM CLEAR SORT ARRAY
980 IFALTHENGOSUB1190:REM START ON 1ST PAGE
990 CLOSE3:OPEN3,3:TA=0
1000 FORJ=1TOG
1010 IFJ=24ORJ=70THENTA=20
1020 IFJ=47THENGOSUB1190:TA=0
1030 GOSUB1240:INPUT#3,TEMP$:NN=VAL(LEFT$(TEMP$,2))
1040 IFNN<1ORNN>GTHENME$="INVALID NUMBER - PLEASE CHANGE":GOSUB1220:GOSUB1260:GOTO930
1050 IFSO%(NN)<>0THENME$="DUPLICATE NUMBER - PLEASE CHANGE":GOSUB1220:GOSUB1260:GOTO930
1060 SO%(NN)=SC%(J)
1070 NEXT:CLOSE3
1080 FORJ=1TOG:SC%(J)=SO%(J):NEXT:REM TRANSFER SORTED KEY #'S TO SC%() ARRAY
1090 GOTO690:REM DISPLAY SORTED DIRECTORY & CONFIRM
1100 REM
1110 REM
1120 REM***********************************************************************
1130 REM SUBROUTINES
1140 REM***********************************************************************
1150 REM*******SUBROUTINE: GET*************************************************
1160 GETQ$:IFQ$=""THEN1160
1170 RETURN
1180 REM******SUBROUTINE: TOGGLE ALTERNATE SCREENS*****************************
1190 AL=NOTAL:IFALTHENPOKE53272,245:POKE648,60:RETURN
1200 POKE 53272,21:POKE648,4:RETURN
1210 REM*******SUBROUTINE: PRINT MESSAGE AT SCREEN BOTTOM**********************
1215 ME$="HIT <F1> TO SEE PAGE "+RIGHT$(STR$(AL+2),1)+"[145]"
1220 SP=39-LEN(ME$):HS=INT(SP/2):PRINTVE$LEFT$(SP$,SP-HS)""ME$"[146]"LEFT$(SP$,HS);:RETURN
1230 REM*******SUBROUTINE: MOVE CURSOR TO ENTRY J******************************
1240 PRINTLEFT$(VE$,J-INT((J-1)/23)*23)TAB(TA);:RETURN
1250 REM*******SUBROUTINE: HIGHLIGHT NUMBER AT ENTRY J*************************
1260 GOSUB1240:PRINT""RIGHT$(STR$(NN),2)"[146] [157]";:RETURN
1261 REM*******SUBROUTINE: READ ERROR CHANNEL
1262 INPUT#15,ER,ER$,TR,SE:IFER>19THENPRINT"[147]"ER;ER$;" TRACK"TR" SECTOR"SE
1263 RETURN
1270 REM *******SUBROUTINE: LOAD "STRING THING" M.L. PROGRAM INTO MEMORY*******
1280 REM STRING MUST BE FIRST VARIABLE
1290 A$="ABCDEFGHIJKLM"
1300 A$=A$+"NOPQRSTUVWXYZ1234"
1310 REM ABOVE SETS STRING FOR 30 CHARS
1320 PRINT"[147]ONE MOMENT PLEASE"
1330 DATA 160, 2, 177, 45, 153, 137, 0, 200, 192, 6, 208
1335 DATA 246, 162, 5, 32, 198, 255, 32, 228, 255, 234
1340 DATA 234, 234, 234, 164, 142, 145, 140, 200, 132, 142
1345 DATA 196, 139, 240, 4, 165, 144, 240, 234, 76, 204
1350 DATA 255, 160, 1, 140, 146, 2, 208, 3, 32, 22
1355 DATA 231, 32, 44, 168, 165, 198, 133, 204, 240, 247
1360 DATA 120, 165, 207, 240, 12, 165, 206, 174, 135, 2
1365 DATA 160, 0, 132, 207, 32, 19, 234, 32, 180, 229
1370 DATA 201, 136, 240, 4, 201, 133, 208, 1, 96, 201
1375 DATA 13, 240, 4, 201, 17, 208, 8, 166, 214, 224
1380 DATA 24, 144, 201, 176, 202, 166, 211, 224, 39, 208
1390 DATA 193, 201, 157, 240, 189, 201, 145, 240, 185, 201
1400 DATA 29, 240, 181, 208, 182, 0, 0
1430 FORJ=896TO1022:READX:POKEJ,X:NEXTJ:J=0
1440 RETURN
1490 PRINT"[147][176]";:FORX=1TO38:PRINT"[177]";:NEXT:PRINT"[174]";
1491 FORX=1TO23:PRINT"[179]"SPC(37)"[171][157][148] ";:NEXT
1492 PRINT"[173]";:FORX=1TO37:PRINT"[178]";:NEXT:PRINT"[189][157][148][178]";
1500 PRINT"";
1510 PRINTSPC(12)"/****** OCTOR"
1520 PRINTSPC(12)"/*******"
1530 PRINTSPC(12)"/**////**"
1540 PRINTSPC(12)"/** /**"
1550 PRINTSPC(12)"/** /**"
1560 PRINTSPC(12)"/** /**"
1570 PRINTSPC(12)"/** /**"
1580 PRINTSPC(12)"/** /**"
1590 PRINTSPC(12)"/*******"
1600 PRINTSPC(12)"/****** IRECTORY"
1610 PRINTSPC(12)"//////"
1620 PRINT:PRINT:PRINT
1630 PRINTSPC(17)"MODIFIED BY":PRINT
1640 PRINTSPC(12)"JAMES P. AMYX"
1642 FORX=1TO1000:NEXT
1643 PRINT:PRINT"[164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164]"
1645 PRINT"INSERT DISK TO BE SORTED, THEN HIT SPACE[146]";
1647 PRINTSPC(6)"[164][164][164][164][164][164][164][164][164][164][164][164]OR[164][164][164][164][164][164][164][164][164][164][164][164]"
1649 PRINTTAB(6)"PRESS "+CHR$(34)+"I"+CHR$(34)+" FOR INSTRUCTIONS[146]"
1650 RETURN
1700 PRINT"[147]"SPC(13)"INSTRUCTIONS":PRINTSPC(13)"[163][163][163][163][163][163][163][163][163][163][163][163]
1710 [153]" DOCTORWAIT DIRECTORYWAIT WILL RE-SORT YOUR"
1720 [153]" DIRECTORY ENTRIES IN ANY ORDER YOU"
1730 [153]" CHOOSE. JUST INSERT THE DISK TO BE"
1740 [153]" SORTED INTO THE DISK DRIVE, THEN HIT
1750 PRINT" THE SPACE BAR.":PRINT:PRINT" THE DIRECTORY ENTRIES WILL BE"
1760 PRINT" DISPLAYED, NUMBERED IN THEIR CURRENT
1770 [153]" ORDER. (NOTE: THE NUMBERS DO NOTWAIT
1780 PRINT" REPRESENT BLOCKS. THEY SIMPLY
1790 [153]" REPRESENT THE ORDER IN WHICH EACH"
1800 [153]" ENTRY APPEARS IN THE DIRECTORY.)"
1810 [153]:[153]" IF YOU WISH TO ALPHABETIZE THE
1820 PRINT" ENTRIES, PRESS THE "CHR$(34)"1"CHR$(34)" KEY, AND
1830 [153]" THE DIRECTORY WILL BE ALPHABETIZED
1835 PRINT" AUTOMATICALLY."
1840 PRINT:PRINT" IF YOU WISH TO SORT THEM IN SOME
1850 [153]" OTHER ORDER, PRESS THE "[199](34)"2"[199](34)" KEY.
1855 PRINT:PRINT" (PRESS ANY KEY TO CONTINUE)[146]";
1857 GET AN$:IF AN$=""THEN1857
1860 PRINT"[147]":PRINT" YOU WILL THEN BE GIVEN CONTROL OF THE
1870 [153]" CURSOR. USING THE NORMAL";
1880 [153]" KEYBOARD":[153]" CONTROLS, RE-NUMBER THE ENTRIES
1890 PRINT" IN ANY ORDER YOU WISH. JUST TYPE
1900 [153]" OVER THE OLD NUMBERS WITH YOUR NEW"
1910 [153]" ONES. WHEN DONE, PRESS THE F7 KEY.
1920 PRINT:PRINT" THE PROGRAM WILL CHECK YOUR NUMBERING
1930 [153]" FOR ERRORS, THEN DISPLAY THE DIRECTORY
1940 PRINT" ENTRIES IN THEIR NEW ORDER, AND ASK
1950 [153]" "[199](34)"OKAY?"[199](34)". IF YOU ANSWER YES, THE
1960 PRINT" NEW DIRECTORY WILL BE WRITTEN TO THE
1970 [153]" DISK. IF YOU ANSWER NO, YOU'LL BE
1980 PRINT" GIVEN THE CHANCE TO RE-DO IT UNTIL
1990 [153]" YOU'RE SATISFIED. TO ABORT, PRESS
2000 PRINT" THE RUN-STOP KEY AT ANY TIME.
2010 [153]:[153]" IF YOUR DIRECTORY HAS MORE THAN 46
2020 PRINT" ENTRIES (MAX=92), IT WILL BE DISPLAYED
2030 [153]" ON TWO SEPARATE PAGES. USE THE F1
2040 PRINT" KEY AT ANY TIME TO FLIP BACK AND
2050 [153]" FORTH BETWEEN THE TWO PAGES.
2060 PRINT:PRINT" (PRESS ANY KEY TO RETURN)[146]";
2070 GETAN$:IFAN$=""THEN2070
2080 RETURN
9000 PRINT"INSERT DOSIT DISK AND PRESS A KEY"
9001 GETA$:IFA$=""THEN9001
9002 PRINT"LOAD"+CHR$(34)+"DOSIT*"+CHR$(34)+",8,1[145][145][145]"
9003 POKE631,1:POKE632,82:POKE633,85:POKE634,78:POKE635,13:POKE198,5
9004 END